package com.zyb.warehouse.controller;

import com.zyb.warehouse.common.Result;
import com.zyb.warehouse.dto.Page;
import com.zyb.warehouse.entity.Store;
import com.zyb.warehouse.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Description:仓库控制层
 */
@RestController
@RequestMapping("/store")
public class StoreController {

    @Autowired
    private StoreService storeService;

    /**
     * 分页查询仓库
     *
     * @param page
     * @param store
     * @return
     */
    @GetMapping("/store-page-list")
    public Result pageStore(Page page, Store store) {
        page = storeService.pageStore(page, store);
        return Result.ok(page);
    }

    /**
     * 查询仓库编号是否重复
     *
     * @param storeNum
     * @return
     */
    @GetMapping("/store-num-check")
    public Result selectStoreByNum(String storeNum) {
        Result result = storeService.queryStoreByNum(storeNum);
        return result;
    }

    /**
     * 添加仓库
     *
     * @param store
     * @return
     */
    @PostMapping("/store-add")
    public Result addStore(@RequestBody Store store) {
        Result result = storeService.addStore(store);
        return result;
    }

    /**
     * 修改仓库
     *
     * @param store
     * @return
     */
    @PutMapping("/store-update")
    public Result modifyStore(@RequestBody Store store) {
        Result result = storeService.updateStore(store);
        return result;
    }

    /**
     * 删除仓库
     *
     * @param storeId
     * @return
     */
    @DeleteMapping("/store-delete/{storeId}")
    public Result deleteStore(@PathVariable("storeId") Integer storeId) {
        Result result = storeService.removeStore(storeId);
        return result;
    }
}
